package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.UserInfo;
import com.lzm.ydpt.module.mall.fragment.MallMineFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.MallMineContract;
import com.lzm.ydpt.mvp.modelimpl.MallMineModelImpl;

import okhttp3.RequestBody;

/**
 * 类名称：MallMainPresenterImpl
 * 类描述：代理实现
 */
public class MallMinePresenterImpl extends BasePresenter implements MallMineContract.Presenter {

    private MallMineContract.View mView;
    private MallMineContract.Model mModel;


    public MallMinePresenterImpl(MallMineFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new MallMineModelImpl();
    }
    @Override
    public void onUserInfoData(RequestBody requestBody) {
        mManager.http(mModel.onUserInfoData(requestBody), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<UserInfo>() {
            @Override
            public void onLoadingResult(BaseResponseBean<UserInfo> entity) {
                mView.onUserInfoData(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onUserInfoData"));
    }
}